import * as ACTIONS from '../../actions/activity-analysis/inviteAction';


/**
 * 数据视图默认状态
 * @type {Object}
 */
export const DEFAULT_DATA_STATE = {
	message: '',
	options: [{
		ID: ACTIONS.TypeOption.InviteTeacher,
		label: '邀请教师统计'
	}, {
		ID: ACTIONS.TypeOption.Telephhone,
		label: '手机号'
	}, {
		ID: ACTIONS.TypeOption.InviteCode,
		label: '邀请码'
	}],
	optInviteTeacherData: {
		isFetching: false,
		data: {}
	},
	optTelephoneData: {
		isFetching: false,
		data: {}
	},
	optInviteCodeData: {
		isFetching: false,
		data: {}
	}
};

export function inviteReducer(state = DEFAULT_DATA_STATE, action = {}) {
	let { type, payload } = action;
	switch(type) {
		case ACTIONS.GET_INVITE_DATA_REQUEST: 
			return Object.assign({}, state, {
				[payload.key]: {
					isFetching: true,
					data: {}
				}
			});
		case ACTIONS.GET_INVITE_DATA_SUCCESS:
			return Object.assign({}, state, {
				[payload.key]: {
					isFetching: false,
					data: payload.data
				}
			})
		case ACTIONS.GET_INVITE_DATA_FAILURE:
			return Object.assign({}, state, {
				message: payload.message,
				[payload.key]: {
					isFetching: false,
					data: {}
				}
			})
		default: 
			return state;
	};
};